$(function () {
    // todos 获取新闻列表
    function fn() {
        $.ajax({
            type: 'GET',
            url: 'http://www.liulongbin.top:3006/api/news',
            success({ data, status, msg }) {
                if (status !== 200) {
                    return alert(msg)
                }
                $('.news-item').html(data.map(item => {
                    const { title, source, cmtcount, time, img } = item
                    let timer = new Date(time)
                    const arr = item.tags.split(',')
                    return `
            <img class="thumb" src="http://www.liulongbin.top:3006${img}" alt="" />
      <div class="right-box">
        <h1 class="title">${title}</h1>
        <div class="tags">
          <span>${arr[0]}</span>
          <span>${arr[1]}</span>
          <span>${arr[2]}</span>
        </div>
        <div class="footer">
          <div>
            <span>${source}</span>&nbsp;&nbsp;
            <span>${timer}</span>
          </div>
          <span>评论数:${cmtcount}</span>
        </div>
      </div>
            ` }).join(''))
            }
        })
    }
    fn()
})
